﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BaHuan.BusinessLayer;
using BaHuan.Common;
using BaHuan.Entities;
namespace BaHuan
{
    public partial class FrmTimKiemPhieuNhapKho : Form
    {
        private PhieuNhapKhoMgt phieunhapkhoMgt = new PhieuNhapKhoMgt();
        private CTPhieuNhapKhoMgt ctphieunhapkhoMgt = new CTPhieuNhapKhoMgt();
        private ChiNhanhCongTyMgt chinhanhcongtyMgt = new ChiNhanhCongTyMgt();

        private NhanVien nhanvien;
        public NhanVien NhanVien
        {
            set { this.nhanvien = value; }
            get { return this.nhanvien; }
        }

        public FrmTimKiemPhieuNhapKho(NhanVien nv)
        {
            InitializeComponent();
            this.NhanVien = nv;
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            DateTime dtTuNgay = dtpTuNgay.Value;
            DateTime dtDenNgay = dtpDenNgay.Value;

            ResultObj result = new ResultObj();
            result = phieunhapkhoMgt.GetAllPhieuNhapKho();

            List<PhieuNhapKho> lstPhieuNhapKho = (from pnk in (List<PhieuNhapKho>)result.Result
                                                  where (pnk.MaSo.ToLower().Contains(txtTimKiem.Text.ToLower()) ||
                                                  pnk.NoiDung.Contains(txtTimKiem.Text) ||
                                                  pnk.chinhanhcongty.TenChiNhanh.Contains(txtTimKiem.Text)) &&
                                                  (pnk.NgayThang.Date >= dtTuNgay.Date && pnk.NgayThang.Date <= dtDenNgay.Date) &&
                                                  pnk.IsDelete==0
                                                  select pnk).ToList();

            dgvTKPhieuNhapKho.AutoGenerateColumns = false;
            dgvTKPhieuNhapKho.DataSource = lstPhieuNhapKho;
        }

        private void dgvTKPhieuNhapKho_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            PhieuNhapKho phieunhapkho = (PhieuNhapKho)dgvTKPhieuNhapKho.CurrentRow.DataBoundItem;

            FrmPhieuNhapKho frmPhieuNhapKho = new FrmPhieuNhapKho(phieunhapkho, nhanvien);
            this.Hide();
            frmPhieuNhapKho.ShowDialog();
            this.Show();
            dgvTKPhieuNhapKho.DataSource = null;
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }        
    }
}
